<article class="module width_full">
    <header><h3>Agregar Tarea <?php echo $this->title_task ?></h3></header>
    <div class="module_content">
        <form style="width: 600px;" class="cmxform" method="post" id="addTareaForm" action="<?php echo $this->url(); ?>">
            <p>
                <label for="title">Titulo *</label>
                <input name="title" id="title"/>
            </p>
            <p>
                <label for="description">Detalle</label>
                <textarea name="description" id="description"></textarea>
            </p>
            <?php if ($this->id_orden == 0) { ?>
                <p>
                    <label for="id_orden">Para la Orden</label>
                    <select id="id_orden" name="id_orden">
                        <option>-- Seleccione una Orden --</option>
                        <?php foreach ($this->resultOrden as $orden) : ?>
                            <option value="<?php echo $orden->id; ?>"><?php echo $orden->code . ' - ' . $orden->title; ?></option>
                        <?php endforeach; ?>
                    </select>
                </p>
                <p>
                    <label for="id_job">Trabajo</label>
                    <select name="id_job" id="id_job">
                        <option value="0">--seleccione el trabajo--</option>
                    </select>
                </p>
            <?php }else { ?>
                <p>
                    <input type="hidden" name="id_orden" id="id_orden" value="<?php echo $this->id_orden ?>"/> 
                </p>
                <p>
                    <label for="id_job">Trabajo</label>
                    <select name="id_job" id="id_job">
                        <option value="0">--seleccione el trabajo--</option>
                        <?php foreach ($this->resultJob as $value) : ?>
                        <option value="<?php echo $value->id ?>"><?php echo $value->name ?></option>
                        <?php endforeach; ?>
                    </select>
                </p>
            <?php } ?>
            <p>
                <label for="id_user">Usuario Asignado</label>
            </p>
            <article class="stats_overview" style="float: left; width: 450px;">
                <div class="overview_today" style="width: 200px; float: left">
                    <?php foreach ($this->resultUserSupervisores as $usersup) : ?>
                        <p style="text-align: left;">
                            <input type="checkbox" class="checkbox" name="checkUser[]" id="checkUser" value="<?php echo $usersup->id ?>"/><?php echo $usersup->nombre . ' ' . $usersup->apellidos ?>
                        </p>
                    <?php endforeach; ?>
                </div>
                <div class="overview_previous" style="width: 200px; float: left">
                    <?php foreach ($this->resultUserDesignerDeveloper as $userd) : ?>
                        <p style="text-align: left;">
                            <input type="checkbox" class="checkbox" name="checkUser[]" id="checkUser" value="<?php echo $userd->id ?>"/><?php echo $userd->nombre . ' ' . $userd->apellidos ?>
                        </p>
                    <?php endforeach; ?>
                </div>
            </article>

            <div class="clear"></div>

            <div class="submit_link" style="margin-top: 10px;">
                <input type="submit" value="Guardar" class="alt_btn"/>
                <a class="button" href="<?php echo $this->url(array('action' => 'view')) ?>">Cerrar</a>
            </div>
        </form>

    </div>
    <footer></footer>
</article>
<script>
    $("#id_orden").change(function(){
        var idOrden = $(this).find("option:selected").val();
        $.ajax({
            type: "GET",
            url: "<?php echo $this->url(array('module' => 'tarea', 'controller' => 'index', 'action' => 'get-jobs')); ?>",
            data: "id_orden="+idOrden,
            success: function(datos){
                $('#id_job').find('option').remove().end().append('<option value="0">--seleccione el trabajo--</option>');
                var dataParse = jQuery.parseJSON(datos);
                $.each(dataParse, function(index, value) {
                    $('#id_job').append('<option value="'+ value.id +'">'+ value.name +'</option>');
                });
            }
        });
    });
</script>